local system = CEGUI.System:getSingleton()
local wmgr = CEGUI.WindowManager:getSingleton()
local cursor = CEGUI.MouseCursor:getSingleton()

wmgr:destroyAllWindows()

local root = wmgr:loadWindowLayout("loadingScreen.layout")
system:setGUISheet(root)

--cursor:hide()

local loading = true

function progressBarUpdated(e)
    if loading then
        local progressBar = CEGUI.toProgressBar(wmgr:getWindow("Root/LoadingBar"))
        local progressMessage = progressBar:getChild("Root/LoadingBar/Message")
        local s = tolua.cast(Overseer:getSingleton():getCurrentState(),"LoadingState")
        local m = s:getStatus()
        progressMessage:setText(m)
        progressBar:setProgress(s:getProgress())
        local e = s:getError()
        if e ~= "" then
            local errorDialog = wmgr:getWindow("Root/ErrorMessage")
            errorDialog:getChild("Root/ErrorMessage/Message"):setText(e)
            errorDialog:setVisible(true)
            loading = false
        end
    end
end

function acknowledgeError(e)
    local titleScreen = TitleScreenState:new(Overseer:getSingleton())
    Overseer:getSingleton():changeState(titleScreen)
end
